import { defineStore } from 'pinia';

export const useKeepAliveStore = defineStore('keepAlive', () => {
    const keepLiveNames = ref<string[]>([]);
    const addKeepLiveName = (name: string) =>
        !keepLiveNames.value.includes(name) && keepLiveNames.value.push(name);
    const removeKeepLiveName = (name: string) =>
        (keepLiveNames.value = keepLiveNames.value.filter(
            (item) => item !== name,
        ));
    const clearMultipleKeepAlive = (_keepLiveNames: string[] = []) =>
        (keepLiveNames.value = _keepLiveNames);
    const setKeepAliveName = (_keepLiveNames: string[] = []) =>
        (keepLiveNames.value = _keepLiveNames);
    return {
        keepLiveNames,
        addKeepLiveName,
        removeKeepLiveName,
        clearMultipleKeepAlive,
        setKeepAliveName,
    };
});
